import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

const routes = [
  { path: '/', NAME: 'Login', meta: { title: '登录' }, component: () => import('@/views/Login.vue') },
  { path: '/register', NAME: 'Register', meta: { title: '注册' }, component: () => import('@/views/Register.vue') },
  { path: '/index', NAME: 'index', meta: { title: '竞拍列表' }, component: () => import('@/views/index.vue') },
  { path: '/auction', NAME: 'Auction', meta: { title: '竞拍页' }, component: () => import('@/views/Auction.vue') },
  { path: '/insert', NAME: 'Insert', meta: { title: '添加商品信息' }, component: () => import('@/views/insert.vue') },
  { path: '/result', NAME: 'Result', meta: { title: '竞拍结果' }, component: () => import('@/views/Result.vue') },
  { path: '/update', NAME: 'Update', meta: { title: '修改商品信息' }, component: () => import('@/views/update.vue') },
  {
    path: '/404', name: '404', meta: { name: '404', title: '404' }, component: () => import('@/views/error/error404.vue')
  },
  {
    path: '/:pathMatch(.*)*', redirect: '/404'
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  next(); // 确保 next() 被正确调用
});

export default router
